/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package linkeddata.arida.ufc.br.gson;

import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *
 * @author jeovane
 */
public class TestJson {
    public static void main(String[] args) {
        Gson gson = new Gson();
        String jsonText = "{" +
                "\"head\": {\n" +
                "    \"vars\": [ \"Drug_name\" , \"Disease_name\" ]\n" +
                "  } ,\n" +
                "  \"results\": {\n" +
                "    \"bindings\": [\n" +
                "      {\n" +
                "        \"Drug_name\": { \"type\": \"literal\" , \"value\": \"Azathioprine (Tablet)\" } ,\n" +
                "        \"Disease_name\": { \"type\": \"literal\" , \"value\": \"\" }\n" +
                "      } ,{\n" +
                "        \"Drug_name\": { \"type\": \"literal\" , \"value\": \"EPIVIR-HBV (Tablet, Coated)\" } ,\n" +
                "        \"Disease_name\": { \"type\": \"literal\" , \"value\": \"\" }\n" +
                "      } ,\n" +
                "      {\n" +
                "        \"Drug_name\": { \"type\": \"literal\" , \"value\": \"IMURAN (Tablet)\" } ,\n" +
                "        \"Disease_name\": { \"type\": \"literal\" , \"value\": \"\" }\n" +
                "      }\n" +
                "    ]\n" +
                "  }" +
                "}";
        
        
        ManipulateJson elemento = gson.fromJson(jsonText, ManipulateJson.class);
        Bindings bindings = new Bindings();
        
        List<String> value = new ArrayList<String>();
        value.add("A");
        value.add("B");
        value.add("C");
        
        String valueMap = "Disease_name";
        //String valueMap = "Drug_name";
        for (int i = 0; i < value.size(); i++) {
            for (int j = 0; j < elemento.getHead().getVars().size(); j++) {
                elemento.getResults().getBindings().get(i).setAtributos(elemento.getHead().getVars().get(j));
            }            
            elemento.getResults().getBindings().get(i).getAtributos().get(valueMap).setValue(value.get(i));
            //elemento.getResults().getBindings().get(i).getDisease_name().setValue(value.get(i));
            //System.out.println(elemento.getResults().getBindings().get(i).getAtributos());
        }
        
        System.out.println(gson.toJson(elemento));
    }
}
